﻿using System;
using System.Diagnostics;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.ObjectBuilder;

namespace CSC440TeamOne.Admin.Views
{
    /// <summary>
    /// Name - ToleranceConfigListPresenter.cs
    /// Description - Encapsulates all client requests from the ToleranceConfigDetailsView
    /// Programmer - Matthew Mitchell
    /// Date coded - 11/27/2011
    /// Arguments - IAdminController
    /// Variables - None
    /// Files accessed by this code artifact - None
    /// Files changed by this code artifact - None
    /// I/O - None
    /// Error Handling - None
    /// Modifications -
    ///     1.0 - Initial coding
    /// Known Faults -
    ///     1.0 - None known
    /// </summary>
    public class ToleranceConfigListPresenter : Presenter<IToleranceConfigListView>
    {
        private IAdminController _controller;

        /// <summary>
        /// Initializes a new instance of the <see cref="ToleranceConfigListPresenter"/> class.
        /// </summary>
        /// <param name="controller">The controller.</param>
        public ToleranceConfigListPresenter([CreateNew] IAdminController controller)
        {
            _controller = controller;
        }

        /// <summary>
        /// Called when [view loaded].
        /// </summary>
        public override void OnViewLoaded()
        {

        }

        /// <summary>
        /// Called when [view initialized].
        /// </summary>
        public override void OnViewInitialized()
        {
            Debug.WriteLine("start ToleranceConfigListPresenter.OnViewInitialized");

            try
            {
                var model = _controller.LoadToleranceConfigItems();

                Debug.Assert(model != null);

                View.Show(model);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                throw;
            }

            Debug.WriteLine("end ToleranceConfigListPresenter.OnViewInitialized");
        }
    }
}




